<%@page import="com.situ.web.entity.Student"%>
<%@page import="com.situ.web.entity.PageBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="/Java1812Web/lib/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
       
</head>
<body>
	<%
	  PageBean pageBean = (PageBean)request.getAttribute("pageBean");
	%>
	<div class="align-center"> 
		<a class="btn btn-success" href="<%=request.getContextPath()%>/addstudent.html">添加学生</a>
		<table class="table table-striped table-bordered table-hover table-condensed">
			<tr>
				<th>编号</th>
				<th>姓名</th>
				<th>年龄</th>
				<th>性别</th>
				<th>删除</th>
				<th>修改</th>
			</tr>
			<%
				for (Student student : pageBean.getList()) {
			%>
					<tr>
						<td><%=student.getId()%></td>
						<td><%=student.getName()%></td>
						<td><%=student.getAge()%></td>
						<td><%=student.getGender()%></td>
						<%-- <td><a href="/Java1812Web/deleteStudent?id=<%=student.getId()%>">删除</a></td> --%>
						<td><a href="javascript:void(0)" onclick="deleteById(<%=student.getId()%>)">删除</a></td>
						<td><a href="<%=request.getContextPath()%>/updateStudent?method=toUpdate&id=<%=student.getId()%>">修改</a></td>
					</tr>
			<%
				}
			%>
		</table>
		<nav aria-label="Page navigation">
		  <ul class="pagination">
	    	<%
	    		if (pageBean.getPageNo() == 1) {
	    	%>
	    		 <li class="disabled">
	    			<a  href="#" aria-label="Previous">
		        		<span aria-hidden="true">&laquo;</span>
		      		</a>
		      	 </li>
		     <% 
	    		} else {
	    	 %>
	    	 	<li>
	    			<a href="<%=request.getContextPath()%>/pageList?pageNo=<%=pageBean.getPageNo()-1%>&pageSize=3" aria-label="Previous">
			        	<span aria-hidden="true">&laquo;</span>
			      	</a>
			    </li>
			 <%
	    		}
			 %>
		    <%
			    for (int i = 1; i <= pageBean.getTotalPage(); i++) {
			    	if (i == pageBean.getPageNo()) {
			%>
			    		 <li class="active"><a href="#"><%=i%></a></li>
			<%
			    	} else {
			%>
			    		<li class=""><a href="<%=request.getContextPath()%>/pageList?pageNo=<%=i%>&pageSize=3"><%=i%></a></li>
			<%
			 	  	}
			    }
		    %>
		    <%
	    		if (pageBean.getPageNo() == pageBean.getTotalPage()) {
	    	%>
	    		 <li class="disabled">
	    			<a  href="#" aria-label="Next">
		        		<span aria-hidden="true">&raquo;</span>
		      		</a>
		      	 </li>
		     <% 
	    		} else {
	    	 %>
	    	 	<li>
	    			<a href="<%=request.getContextPath()%>/pageList?pageNo=<%=pageBean.getPageNo()+1%>&pageSize=3" aria-label="Previous">
			        	<span aria-hidden="true">&raquo;</span>
			      	</a>
			    </li>
			 <%
	    		}
			 %>
		  </ul>
		</nav>
		<script type="text/javascript">
			function deleteById(id){
				//用户点击确定，confirm返回的是true
				//用户点击取消，confirm返回的是false
				var isDel = confirm("您确定要删除么？");
				if (isDel) {
					location.href = "<%=request.getContextPath()%>/deleteStudent?id=" + id;
				}
			}
		</script>
	</div>
</body>
</html>